package aiball

import components.GlobalConstants;

class ContentService {

	public getContentLinks() {

		def links = "";
		def contents = Contents.findAllByParent(Contents.get(1));

		for(int i = 0;i<contents.size();i++) {
				
			
				links += "<ul><li>";

				if(!contents.get(i).justCategory) {
					links += "<a href=\"" + GlobalConstants.URL_PATH + "/contents/show/" + contents.get(i).id + "\">";
				}

				links += "<h4>" + contents.get(i).name + "</h4>";
				
				def subCont = Contents.findAllByParent(contents.get(i));
				
				if(!subCont.empty)
				{
				
				links += "<ul>";


					for(int j = 0;j<subCont.size();j++) {
						links += "<li><a href=\"" + GlobalConstants.URL_PATH + "/contents/show/" + subCont.get(j).id + "\">";
						links += "<h4>" + subCont.get(j).name + "</h4>";
							links += "</a>";
						links += "</li>\n";
					}
					
					links += "</ul>";
					
				}
				

				if(!contents.get(i).justCategory) {
					links += "</a>";
				}
				
				
				

				links += "</li></ul>\n";
				
			
			//links +="<ul><a href=\"contents/show/" + contents.get(i).id + "\"><h4>" + contents.get(i).name + "</h4></a></ul>\n"
		}

		return links;
	}
}
